import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ShopConfig } from "../../resource/ShopConfig";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { BaseItem } from "../common/BaseItem";
import { Language } from "../../../../extend/language/Language";
import { NumInput } from "../common/NumInput";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { Alert } from "../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { _shopItemInfo } from "../../../../this/_shopItemInfo";
type int = number;
//class DrugBagCellRenderer
    
    export  class DrugBagCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._itemCode = arg1 as int;
            this._shopItemInfo = ShopConfig.instance.getShopItemInfoByCode(this._itemCode);
            if (this._shopItemInfo) 
            {
                this._baseItem.itemData = new ItemData(this._itemCode);
                this._priceTxt.text = this._shopItemInfo.tshopSell.price.toString();
            }
            if (ItemsUtil.isVIPItem(this._shopItemInfo)) 
            {
                this._labelBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.VIPLabel);
            }
            else 
            {
                this._labelBitmap.bitmapData = null;
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 230, 80, this);
            ObjCreate.createBg(27, 8, 68, 68, this);
            this._baseItem = new BaseItem();
            this._baseItem.isDragAble = false;
            this._baseItem.isDropAble = false;
            this._baseItem.setSize(62, 62);
            this._baseItem.move(29, 10);
            this.addChild(this._baseItem);
            this._labelBitmap = ObjCreate.createBitmap(ImagesConst.VIPLabel, 15, 5, this);
            ObjCreate.createTextField(Language.getString(41283), 113, 7, 40, 20, this);
            this._priceTxt = ObjCreate.createTextField("", 152, 7, 40, 20, this);
            this._unitBitmap = GlobalClass.getBitmap(ImagesConst.Yuanbao_small);
            this._unitBitmap.x = 180;
            this._unitBitmap.y = 7;
            this.addChild(this._unitBitmap);
            this._numInput = new NumInput();
            this._numInput.minNum = 1;
            this._numInput.setMaxNum(99);
            this._numInput.x = 113;
            this._numInput.y = 27;
            this.addChild(this._numInput);
            this._buyBtn = ObjCreate.createGButton(Language.getString(41284), 117, 50, 80, 24, this);
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickHandler);
            this._buyBtn.drawNow();
            return;
        }

        /* internal  */onBuyBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (ItemsUtil.isVIPItem(this._shopItemInfo) && !Cache.instance.vip.isVIP) 
            {
                MsgManager.showRollTipsMsg(Language.getString(35969));
                return;
            }
            var loc1=!PulseSharedObject.isTodayNotTips("DrugBagBuyAlert");
            if (loc1) 
            {
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(Language.getStringByParam(41285, this._numInput.currentNum, "#00ff00", this._shopItemInfo.itemInfo.item.name, this._numInput.currentNum * this._shopItemInfo.tshopSell.price), null, Alert.OK | Alert.CANCEL, null, this.onClose);
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItemAndUse, {"shopItemInfo": _shopItemInfo, "amount": this._numInput.currentNum}));
            }
            return;
        }

        /* internal  */onClose(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItemAndUse, {"shopItemInfo": _shopItemInfo, "amount": this._numInput.currentNum}));
                Alert.resetToDefault();
            }
            if (arg2) 
            {
                PulseSharedObject.save("DrugBagBuyAlert", true);
            }
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_numInput: NumInput;

        /* internal */ /* var */_buyBtn: GButton;

        /* internal */ /* var */_labelBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemCode: int;

        /* internal */ /* var */_shopItemInfo: ShopItemInfo;
    }
